#include <iostream>
#include "client.hpp"
#include "Log.hpp"
using namespace std;

std::string name;
std::string password;
std::string db;
const std::string clientip = "127.0.0.1";
const static int  keyerrortimes = 3;//输错密码的最大限度


int main()
{   
    bool situation = true;
    int pos = 0;//标记输入密码的次数
    while(pos < keyerrortimes)
    {
        cout << "请输入账户名称~ " << endl;
        getline(cin, name);
        cout << "请输入账户密码~ " << endl;
        getline(cin, password);
        cout << "请输入你想要使用的数据库名称~ " << endl;
        getline(cin, db);
        CT::Client client(name, "2593hyK.", "libary_managment", &situation, "127.0.0.1");
        if(!situation){//密码输入错误
            pos++;
            lg.LogMessage(Error, "密码输入错误请重新输入~\n");
            continue;
        }
        lg.LogMessage(Info, "登录成功，请输入你需要的服务：\n1.借书，2.还书，3.查看书籍信息\n");

        int n;//服务序号
        //string book;
        cin >> n;
        switch(n)
        {
        case 1:
            client.BorrowBook();
            break;
        case 2:
            client.ReturnBook();
            break;
        case 3:
            client.ShowDetails();
            break;
        case 0:
            cout << "准备退出"  << endl;
            client.Quit();
            exit(0);
        default:
            break;
        }
    }
    if(pos >= keyerrortimes){
        cout << "密码输入错误次数过多，请请稍后再试~" << endl;
        return 1;
    }
    return 0;
}